package com.kmust.dream.wanderingdream.product.controller;

import com.kmust.dream.wanderingdream.comm.pojo.ResultBean;
import com.kmust.dream.wanderingdream.product.entity.ProductDetailImage;
import com.kmust.dream.wanderingdream.product.service.ProductDetailImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product/productDetailImage")
@Api(value = "商品详情图片API")
public class ProductDetailImageController {
    @Autowired
    ProductDetailImageService productDetailImageService;

    /**
     * 根据productId获取对应的详情图片
     *
     * @param productId 商品id
     * @return resultBean
     */
    @ApiOperation(value = "根据主键获取对应的所有详情图片",notes = "参数是商品的主键productId")
    @GetMapping("/getAllDetailImage/{productId}")
    public ResultBean getAllDetailImage(@PathVariable Integer productId) {
        return productDetailImageService.getAllDetailImage(productId);
    }


    /**
     * 添加图片
     *
     * @param productDetailImage 详情图片对象，json
     * @return resultBean
     */
    @ApiOperation(value = "添加详情图片",notes = "参数是详情图片json字符串")
    @PostMapping("/addDetailImage")
    public ResultBean addDetailImage(@RequestBody ProductDetailImage productDetailImage) {
        return productDetailImageService.addDetailImage(productDetailImage);
    }

    @ApiOperation(value = "批量添加详情图片",notes = "参数是详情图片json字符串数组")
    @PostMapping("/addDetailImageBatch")
    public ResultBean addDetailImageBatch(@RequestBody List<ProductDetailImage> images) {
        System.out.println(images);
        return productDetailImageService.addDetailImageBatch(images);
    }


}
